package thread.threaddemo;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/03/16:14
 * @Description:拿到线程的名称以及线程的ID
 */
public class ThreadDemo13 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable=new Runnable() {
            @Override
            public void run() {
               //先拿到当前线程
               Thread t=Thread.currentThread();
               //在拿到当前线程的一个ID
                System.out.println("线程的ID"+t.getId());
                //在拿到当前线程的一个名称
                System.out.println("线程的Name"+t.getName());
            }
        };
        //创建线程给分配任务以及名称
        Thread thread=new Thread(runnable,"线程1");
        thread.start();

        //要是想要分行
        Thread.sleep(500);
        System.out.println();

        Thread thread1=new Thread(runnable,"线程2");
        thread1.start();
    }
}
